<template>
     <div class="content">
        <Collapse v-model="value1">
          <Panel name="1">
              常规设置
              <div slot="content">
                  <Form label-position="right" :label-width="100">
                    <div class="canshu">
                        <FormItem label="日启动套利次数：" :label-width="120">
                              BTC <Input class="w80" v-model="lhbao.GoConfigBtc.startNum" />
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="keppStartNum(lhbao.GoConfigBtc.id,lhbao.GoConfigBtc.startNum)" size="large">保　存</Button>
                          </div>
                    </div>
                    <div class="canshu">
                        <FormItem label="" :label-width="120">
                              ETH <Input class="w80" v-model="lhbao.GoConfigEth.startNum" />
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="keppStartNum(lhbao.GoConfigEth.id,lhbao.GoConfigEth.startNum)" size="large">保　存</Button>
                          </div>
                    </div>
                    <!-- <div class="canshu">
                        <FormItem label="启动套利时间间隔：" :label-width="120">
                              BTC <Input class="w80" v-model="lhbao.GoConfigBtc.startSpace" /> / 分钟
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="kepptime(lhbao.GoConfigBtc.id,lhbao.GoConfigBtc.startSpace)" size="large">保　存</Button>
                          </div>
                    </div>
                    <div class="canshu">
                        <FormItem label="" :label-width="120">
                              ETH <Input class="w80" v-model="lhbao.GoConfigEth.startSpace" /> / 分钟
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="kepptime(lhbao.GoConfigEth.id,lhbao.GoConfigEth.startSpace)" size="large">保　存</Button>
                          </div>
                    </div> -->
                    <div class="canshu">
                        <FormItem label="BTC启动方式：">
                              <Select placeholder="请选择启动方式" class="w100 m-r10" v-model="mode.goStartBtc.startId">
                                  <Option value="1">手动</Option>
                                  <Option value="2">自动</Option>
                              </Select>
                          </FormItem>
                          <FormItem v-show="mode.goStartBtc.startId == 1 ? false : true" label="差价">
                              <Input class="w80" v-model="mode.goStartBtc.spread" /> / $
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="keppqd(mode.goStartBtc.id,mode.goStartBtc.startId,mode.goStartBtc.spread)" size="large">保　存</Button>
                          </div>
                          <div class="p-10" v-show="mode.goStartBtc.startId == 2 ? false : true">
                              <Button type="info" @click="qidongbtc" size="large">启 动</Button>
                          </div>
                    </div>
                    <div class="canshu">
                        <FormItem label="ETH启动方式：">
                              <Select placeholder="请选择启动方式" class="w100 m-r10" v-model="mode.goStarteth.startId">
                                  <Option value="1">手动</Option>
                                  <Option value="2">自动</Option>
                              </Select>
                          </FormItem>
                          <FormItem v-show="mode.goStarteth.startId == 1 ? false : true" label="差价">
                              <Input class="w80" v-model="mode.goStarteth.spread" /> / $
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="keppqd(mode.goStarteth.id,mode.goStarteth.startId,mode.goStarteth.spread)" size="large">保　存</Button>
                          </div>
                          <div class="p-10" v-show="mode.goStarteth.startId == 2 ? false : true">
                              <Button type="info" @click="qidongeth" size="large">启 动</Button>
                          </div>
                    </div>
                    <div class="canshu">
                            <FormItem label="退出机制：">
                              BTC: 本金 <Input class="w80" v-model="lhbao.GoConfigBtc.lessDayPrincipalFee" /> % , 收益 <Input class="w80" v-model="lhbao.GoConfigBtc.lessDayIncomeFee" /> % ≤ <Input class="w80" v-model="lhbao.GoConfigBtc.day" /> 天 < 本金 <Input class="w80" v-model="lhbao.GoConfigBtc.greaterDayPrincipalFee" /> % , 收益 <Input class="w80" v-model="lhbao.GoConfigBtc.greaterDayIncomeFee" /> %
                            </FormItem>
                            <div class="p-10">
                              <Button type="primary" @click="kepplout(lhbao.GoConfigBtc.id,lhbao.GoConfigBtc.lessDayPrincipalFee,lhbao.GoConfigBtc.lessDayIncomeFee,lhbao.GoConfigBtc.day,lhbao.GoConfigBtc.greaterDayPrincipalFee,lhbao.GoConfigBtc.greaterDayIncomeFee)" size="large">保　存</Button>
                            </div>
                        </div>
                        <div class="canshu">
                            <FormItem label="">
                              ETH: 本金 <Input class="w80" v-model="lhbao.GoConfigEth.lessDayPrincipalFee" /> % , 收益 <Input class="w80" v-model="lhbao.GoConfigEth.lessDayIncomeFee" /> % ≤ <Input class="w80" v-model="lhbao.GoConfigEth.day" /> 天 < 本金 <Input class="w80" v-model="lhbao.GoConfigEth.greaterDayPrincipalFee" /> % , 收益 <Input class="w80" v-model="lhbao.GoConfigEth.greaterDayIncomeFee" /> %
                            </FormItem>
                            <div class="p-10">
                              <Button type="primary" @click="kepplout(lhbao.GoConfigEth.id,lhbao.GoConfigEth.lessDayPrincipalFee,lhbao.GoConfigEth.lessDayIncomeFee,lhbao.GoConfigEth.day,lhbao.GoConfigEth.greaterDayPrincipalFee,lhbao.GoConfigEth.greaterDayIncomeFee)" size="large">保　存</Button>
                            </div>
                        </div>

                        <div class="canshu">
                        <FormItem label="日收益封顶：">
                              BTC <Input class="w80" v-model="lhbao.GoConfigBtc.caps" /> %
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="keppcaps1(lhbao.GoConfigBtc.id,lhbao.GoConfigBtc.caps)" size="large">保　存</Button>
                          </div>
                        </div>
                        <div class="canshu">
                        <FormItem label="">
                              ETH <Input class="w80" v-model="lhbao.GoConfigEth.caps" /> %
                          </FormItem>
                          <div class="p-10">
                              <Button type="primary" @click="keppcaps1(lhbao.GoConfigEth.id,lhbao.GoConfigEth.caps)" size="large">保　存</Button>
                          </div>
                        </div>
                  </Form>
              </div>
          </Panel>
          <Panel name="2">
              推荐收益
              <div slot="content">
                  <Form label-position="right" :label-width="100">
                    <div class="canshu">
                            <FormItem label="等级配置：">
                                <!-- BTC：收益等级 <Input class="w80" v-model="btcgrade1" />   -->
                                BTC： 收益百分比 <Input class="w80" v-model="btcincomeNum1" placeholder="请添加" /> %
                            </FormItem>
                            <div class="p-10">
                              <Button type="info" @click="addbtc(btcincomeNum1)" size="large">添 加</Button>
                            </div>
                        </div>
                         <FormItem label="收益：">
                             <div class="canshu" v-for="(item,index) in lhbao.goGradeBtc" :key="item.id">
                                  <FormItem>
                                      收益等级 <Input class="w50" v-model="item.grade" disabled />  收益百分比 <Input class="w80" v-model="item.incomeNum" /> %
                                  </FormItem>
                                  <div class="p-10">
                                    <Button type="error" @click="delbtc(item.id)" :disabled='index == lhbao.goGradeBtc.length-1 ? false : true' size="large">删 除</Button>
                                  </div>
                                  <div class="p-10">
                                    <Button type="primary" @click="keppbtc(item.id,item.incomeNum)" size="large">保　存</Button>
                                  </div>
                                </div>
                         </FormItem>
                        <div class="canshu">
                            <FormItem label="等级配置：">
                                <!-- ETH：收益等级 <Input class="w80" v-model="ethgrade1" />   -->
                               ETH： 收益百分比 <Input class="w80" v-model="ethincomeNum1" placeholder="请添加" /> %
                            </FormItem>
                            <div class="p-10">
                              <Button type="info" @click="addeth(ethincomeNum1)" size="large">添 加</Button>
                            </div>
                        </div>

                            <FormItem label="收益：">

                                <div class="canshu" v-for="(item,index) in lhbao.goGradeEth" :key="item.id">
                                  <FormItem>
                                      收益等级 <Input class="w50" v-model="item.grade" disabled />  收益百分比 <Input class="w80" v-model="item.incomeNum" /> %
                                  </FormItem>
                                  <div class="p-10">
                                    <Button type="error" @click="deleth(item.id)" :disabled='index == lhbao.goGradeEth.length-1 ? false : true' size="large">删 除</Button>
                                  </div>
                                  <div class="p-10">
                                    <Button type="primary" @click="keppeth(item.id,item.incomeNum)" size="large">保　存</Button>
                                  </div>
                                </div>
                            </FormItem>

                  </Form>
              </div>
          </Panel>
        </Collapse>
        <Modal @on-ok="confirm"
        title="启动提示"
        v-model="modal8"
        :closable="false"
        :styles="{top: '300px'}"
        :mask-closable="false">
        <p style="text-align: center; font-size:18px; color: #76A1F2">{{ tishi }}</p>
    </Modal>
     </div>
</template>

<script>
export default {
  data () {
    return {
      tishi:'正在启动中',
      modal8:false,
      // disabled: true,
      lhbao: {}, // 量化宝
      mode: {}, // 启动方式
      value1: '1',
      // btcgrade1: '',
      btcincomeNum1: '',
      // ethgrade1: '',
      ethincomeNum1: ''
    }
  },
  methods: {
    // 查询量化宝参数
    getLhb () {
      let token = localStorage.getItem('mytoken')
      this.axios
        .get('parameter/go/config', {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.lhbao = res.data.data
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 查询量化宝启动方式
    getGo () {
      let token = localStorage.getItem('mytoken')
      this.axios
        .get('parameter/go/start', {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.mode = res.data.data
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 修改量化宝启动方式
    keppqd (id, start, spread) {
      let token = localStorage.getItem('mytoken')
      let reg = /[^\d^\.]+/g
      // if (spread === '') {
      //   this.$Message.info('差价不能为空')
      //   return false
      // }
      let qd = reg.test(spread)
      if (qd) {
        this.$Message.info('请输入正数')
        return false
      }
      let params = this.qs.stringify({
        id: id,
        start: start,
        spread: spread
      })
      this.axios.put('parameter/go/start', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        if (res.data.code == 8008) {
          this.getGo()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    confirm() {
      this.tishi = '正在启动中'
    },
    // 启动btc
    qidongbtc() {
      this.modal8 = true
      let token = localStorage.getItem('mytoken')
      this.axios
        .get('parameter/go/start/btc/mt', {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          if (res.data.code == 8008) {
            this.getLhb()
            this.tishi = res.data.message
            this.$Message.info(res.data.message)
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 启动eth
    qidongeth() {
      this.modal8 = true
      let token = localStorage.getItem('mytoken')
      this.axios
        .get('parameter/go/start/eth/mt', {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          if (res.data.code == 8008) {
            this.getLhb()
            this.tishi = res.data.message
            this.$Message.info(res.data.message)
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 添加量化宝btc推荐收益等级
    addbtc (incomeNum) {
      let reg = /[^\d^\.]+/g

      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        incomeNum: incomeNum
      })
      this.axios
        .post('parameter/go/btcgrade', params, {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.getLhb()
            this.$Message.info(res.data.message)
            this.btcincomeNum1 = null
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 删除量化宝btc推荐收益等级
    delbtc (id) {
      let token = localStorage.getItem('mytoken')
      this.axios.delete('parameter/go/btcgrade/' + id, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改量化宝btc推荐收益等级
    keppbtc (id,incomeNum) {
      let reg = /[^\d^\.]+/g
      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        incomeNum: incomeNum
      })
      this.axios.put('parameter/go/btcgrade', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 添加量化宝eth推荐收益等级
    addeth (incomeNum) {
      let reg = /[^\d^\.]+/g

      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        incomeNum: incomeNum
      })
      this.axios
        .post('parameter/go/ethgrade', params, {
          headers: {
            Authorization: 'bearer ' + token
          }
        })
        .then(res => {
          // console.log(res)
          if (res.data.code == 8008) {
            this.getLhb()
            this.$Message.info(res.data.message)
            this.ethincomeNum1 = null
          } else if (res.data.code == 4004) {
            this.$Message.info(res.data.message)
          } else if (res.data.code == 5501) {
            this.$Message.info(res.data.message)
            localStorage.removeItem('mytoken')
            this.$router.push({name: 'login'})
          }
        })
    },
    // 删除量化宝eth推荐收益等级
    deleth (id) {
      let token = localStorage.getItem('mytoken')
      this.axios.delete('parameter/go/ethgrade/' + id, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改量化宝eth推荐收益等级
    keppeth (id,incomeNum) {
      let reg = /[^\d^\.]+/g
      let shouyi = reg.test(incomeNum)
      if (shouyi) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        incomeNum: incomeNum
      })
      this.axios.put('parameter/go/ethgrade', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改量化宝日启动次数
    keppStartNum (id, startNum) {
      let reg = /[^\d^\.]+/g
      if (startNum === '') {
        this.$Message.info('日启动次数不能为空')
        return false
      }
      let cs = reg.test(startNum)
      if (cs) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        startNum: startNum
      })

      this.axios.put('parameter/go/config', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改量化宝启动时间间隔
    // kepptime (id, startSpace) {
    //   let reg = /[^\d^\.]+/g
    //   if (startSpace === '') {
    //     this.$Message.info('日启动次数不能为空')
    //     return false
    //   }
    //   let time = reg.test(startSpace)
    //   if (time) {
    //     this.$Message.info('请输入正数')
    //     return false
    //   }

    //   let token = localStorage.getItem('mytoken')
    //   let params = this.qs.stringify({
    //     id: id,
    //     startSpace: startSpace
    //   })

    //   this.axios.put('parameter/go/config', params, {
    //     headers: {
    //       Authorization: 'bearer ' + token
    //     }
    //   }).then(res => {
    //     // console.log(res)
    //     if (res.data.code == 8008) {
    //       this.getLhb()
    //       this.$Message.info(res.data.message)
    //     } else if (res.data.code == 4004) {
    //       this.$Message.info(res.data.message)
    //     } else if (res.data.code == 5501) {
    //       this.$Message.info(res.data.message)
    //       localStorage.removeItem('mytoken')
    //       this.$router.push({name: 'login'})
    //     }
    //   })
    // },
    // 修改量化宝退出机制
    kepplout (id, lessDayPrincipalFee, lessDayIncomeFee, day, greaterDayPrincipalFee, greaterDayIncomeFee) {
      let reg = /[^\d^\.]+/g
      if (lessDayPrincipalFee === '') {
        this.$Message.info('最低本金不能为空')
        return false
      }
      if (lessDayIncomeFee === '') {
        this.$Message.info('最低收益不能为空')
        return false
      }
      if (day === '') {
        this.$Message.info('天数不能为空')
        return false
      }
      if (greaterDayPrincipalFee === '') {
        this.$Message.info('最高本金不能为空')
        return false
      }
      if (greaterDayIncomeFee === '') {
        this.$Message.info('最高收益不能为空')
        return false
      }

      let lhb1 = reg.test(lessDayPrincipalFee)
      if (lhb1) {
        this.$Message.info('请输入正数')
        return false
      }
      let lhb2 = reg.test(lessDayIncomeFee)
      if (lhb2) {
        this.$Message.info('请输入正数')
        return false
      }
      let lhb3 = reg.test(day)
      if (lhb3) {
        this.$Message.info('请输入正数')
        return false
      }
      let lhb4 = reg.test(greaterDayPrincipalFee)
      if (lhb4) {
        this.$Message.info('请输入正数')
        return false
      }
      let lhb5 = reg.test(greaterDayIncomeFee)
      if (lhb5) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        greaterDayPrincipalFee: greaterDayPrincipalFee,
        greaterDayIncomeFee: greaterDayIncomeFee,
        day: day,
        lessDayPrincipalFee: lessDayPrincipalFee,
        lessDayIncomeFee: lessDayIncomeFee
      })

      this.axios.put('parameter/go/config', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    },
    // 修改稳健基金日封顶
    keppcaps1 (id, caps) {
      let reg = /[^\d^\.]+/g
      if (caps === '') {
        this.$Message.info('日收益封顶不能为空')
        return false
      }
      let wj = reg.test(caps)
      if (wj) {
        this.$Message.info('请输入正数')
        return false
      }

      let token = localStorage.getItem('mytoken')
      let params = this.qs.stringify({
        id: id,
        caps: caps
      })

      this.axios.put('parameter/go/config', params, {
        headers: {
          Authorization: 'bearer ' + token
        }
      }).then(res => {
        // console.log(res)
        if (res.data.code == 8008) {
          this.getLhb()
          this.$Message.info(res.data.message)
        } else if (res.data.code == 4004) {
          this.$Message.info(res.data.message)
        } else if (res.data.code == 5501) {
          this.$Message.info(res.data.message)
          localStorage.removeItem('mytoken')
          this.$router.push({name: 'login'})
        }
      })
    }
  },
  created () {
    this.getLhb()
    this.getGo()
  },
  mounted () {
    this.$Message.config({
      top: 250
    })
  }
}
</script>

<style lang="less" scoped>
.p-10 {
  padding-top: 0 !important;
  padding-left: 50px !important;
}
.w50 {
  width: 50px !important;
}
.mar {
  margin-left: 5px;
}
</style>
